//
//  ZXNewFeatureController.m
//  ZXOCWeiBo
//
//  Created by mac on 15/12/2.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZXNewFeatureController.h"
#import "ZXBeginView.h"

@interface ZXNewFeatureController ()<UIScrollViewDelegate>

@property(nonatomic,weak)UIPageControl * PageControl;

@end

@implementation ZXNewFeatureController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    //创建scrollView
    UIScrollView * scrollView = [[UIScrollView alloc]init];
    scrollView.delegate = self;
    scrollView.frame = self.view.frame;
    //去除滚动条
    scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    
  
    
    CGFloat imgW = scrollView.w;
    CGFloat imgH = scrollView.h;
    CGFloat imgX = 0;
    CGFloat imgY = 0;
    
    for (NSInteger i = 1; i< 5 ; i++)
    {
        
        UIImageView * imgView = [[UIImageView alloc]init];
        NSString * imgName = [NSString stringWithFormat:@"new_feature_%ld",i];
        imgView.image = [UIImage imageNamed:imgName];
        
        imgX = (i - 1)*imgW;
        imgView.frame = CGRectMake(imgX, imgY, imgW, imgH);
        
        if (i == 4)
        {
            imgView.userInteractionEnabled = YES;
            //创建按钮
            ZXBeginView * beginView = [ZXBeginView beginView];
            
            CGFloat centerX = imgW * 0.5;
            CGFloat centerY = imgH * 0.5 + 200;
            beginView.center = CGPointMake(centerX, centerY);
            [imgView addSubview:beginView];
        }
        
        [scrollView addSubview:imgView];
        
    }
    
    //设置滚动范围
    scrollView.contentSize = CGSizeMake(imgW * 4, imgH);
//    设置翻页属性
    scrollView.pagingEnabled = YES;
    
    //设置
    UIPageControl * pageControl = [[UIPageControl alloc]init];
//    底部间距
    CGFloat bottomMargin = 60;
    CGFloat pagH = 20;
    CGFloat pagY = self.view.h - bottomMargin - pagH;
    pageControl.frame = CGRectMake(0,pagY , self.view.w, pagH);
//    pageControl.backgroundColor = [UIColor orangeColor];
    pageControl.numberOfPages = 4;
    
    pageControl.pageIndicatorTintColor = [UIColor grayColor];
    pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    self.PageControl = pageControl;
    
    
    [self.view addSubview:pageControl];
    
  
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
  NSInteger i = scrollView.contentOffset.x / scrollView.w;
    self.PageControl.currentPage = i;
}

@end
